import 'package:flutter/cupertino.dart';

export 'encrypttool.dart';
export 'extension_int.dart';

import 'package:flutter/material.dart';






class NavKey{
  static final navigatorKey = GlobalKey<NavigatorState>();
  static BuildContext? getCurrentContext(){
    return navigatorKey.currentState?.overlay?.context;
  }
}

String scaleX() {
  BuildContext? context = NavKey.getCurrentContext();
  int devicePixelRatio = 2;
  if (context != null) {
     devicePixelRatio = MediaQuery.of(context!).devicePixelRatio.floor();
  }
  String scale =
      '${devicePixelRatio}x';
  return scale;
}

String assetHome(String imageName) {
  return 'assets/home/${scaleX()}/';
}

String assetImage(String imageName) {
  return 'assets/image/$imageName@${scaleX()}.png';
}







String assetTabbar(String imageName) {
  return 'assets/tabbar/${scaleX()}/$imageName';
}



String assetProfile(String imageName) {
  return 'assets/profile/${scaleX()}/';
}




// 可以在utils定义log.dart
void printLog(Object message, StackTrace current) {
  MYCustomTrace programInfo = MYCustomTrace(current);
  print("文件: ${programInfo.fileName}, 行: ${programInfo.lineNumber}, 打印信息: $message");
}

class MYCustomTrace {
  final StackTrace _trace;
  String? fileName;
  int? lineNumber;
  int? columnNumber;

  MYCustomTrace(this._trace) {
    _parseTrace();
  }

  void _parseTrace() {
    var traceString = this._trace.toString().split("\n")[0];
    var indexOfFileName = traceString.indexOf(RegExp(r'[A-Za-z_]+.dart'));
    var fileInfo = traceString.substring(indexOfFileName);
    var listOfInfos = fileInfo.split(":");
    this.fileName = listOfInfos[0];
    this.lineNumber = int.parse(listOfInfos[1]);
    var columnStr = listOfInfos[2];
    columnStr = columnStr.replaceFirst(")", "");
    this.columnNumber = int.parse(columnStr);
  }
}
